<html>
<head><meta charset="utf-8"><title>const generics · t-compiler/const-eval · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/index.html">t-compiler/const-eval</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20generics.html">const generics</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="170780423"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20generics/near/170780423" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20generics.html#170780423">(Jul 13 2019 at 08:10)</a>:</h4>
<p>using const generics broke miri for some array stuff, we likely need to do <em>something</em> to monomorphize them or so? No idea what and how though. See <a href="https://github.com/rust-lang/rust/pull/62435#issuecomment-511100890" target="_blank" title="https://github.com/rust-lang/rust/pull/62435#issuecomment-511100890">https://github.com/rust-lang/rust/pull/62435#issuecomment-511100890</a>.<br>
<span class="user-mention" data-user-id="124288">@oli</span> I think I need your help for this.</p>



<a name="170780444"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20generics/near/170780444" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20generics.html#170780444">(Jul 13 2019 at 08:11)</a>:</h4>
<p>Uh. I was hoping that would be transparent for us. I thought these were fixes in the engine.</p>



<a name="170780446"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20generics/near/170780446" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20generics.html#170780446">(Jul 13 2019 at 08:11)</a>:</h4>
<p>Are you by any chance getting an ICE?</p>



<a name="170780489"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20generics/near/170780489" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20generics.html#170780489">(Jul 13 2019 at 08:12)</a>:</h4>
<p>Ah no</p>



<a name="170780490"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20generics/near/170780490" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20generics.html#170780490">(Jul 13 2019 at 08:12)</a>:</h4>
<p>They are just bailing outnow</p>



<a name="170780504"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20generics/near/170780504" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20generics.html#170780504">(Jul 13 2019 at 08:13)</a>:</h4>
<p>I thought i left some comments to not just bail out</p>



<a name="170780510"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20generics/near/170780510" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20generics.html#170780510">(Jul 13 2019 at 08:13)</a>:</h4>
<p>Oh well</p>



<a name="170780561"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20generics/near/170780561" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20generics.html#170780561">(Jul 13 2019 at 08:14)</a>:</h4>
<p>I wonder why monomorphization doesn't catch this</p>



<a name="170780565"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20generics/near/170780565" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20generics.html#170780565">(Jul 13 2019 at 08:14)</a>:</h4>
<p>We may nees to replicate some codegen changes from that PR in the engine</p>



<a name="170780573"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20generics/near/170780573" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20generics.html#170780573">(Jul 13 2019 at 08:15)</a>:</h4>
<p>I'll try to find some time next week</p>



<a name="170780632"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20generics/near/170780632" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20generics.html#170780632">(Jul 13 2019 at 08:16)</a>:</h4>
<p>the error is</p>
<div class="codehilite"><pre><span></span>error[E0080]: Miri evaluation error: encountered overly generic constant
   --&gt; /home/r/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libcore/array.rs:337:16
    |
337 |             if slice.len() == N {
    |                ^^^^^^^^^^^^^^^^ Miri evaluation error: encountered overly generic constant
    |
note: inside call to `std::array::impls_using_const_generics::&lt;impl std::convert::TryFrom&lt;&amp;[u8]&gt; for &amp;[u8; 0]&gt;::try_from` at core_miri_test/../libcore/tests/array.rs:31:30
   --&gt; core_miri_test/../libcore/tests/array.rs:31:30
    |
31  |                   let result = &lt;&amp;Array&gt;::try_from(slice);
    |                                ^^^^^^^^^^^^^^^^^^^^^^^^^
...
36  | /     test! {
37  | |          0  1  2  3  4  5  6  7  8  9
38  | |         10 11 12 13 14 15 16 17 18 19
39  | |         20 21 22 23 24 25 26 27 28 29
40  | |         30 31 32
41  | |     }
    | |_____- in this macro invocation
note: inside call to `array::array_try_from` at core_miri_test/../libcore/tests/array.rs:23:1
   --&gt; core_miri_test/../libcore/tests/array.rs:23:1
    |
23  | / fn array_try_from() {
24  | |     macro_rules! test {
25  | |         ($($N:expr)+) =&gt; {
26  | |             $({
...   |
41  | |     }
42  | | }
    | |_^
    = note: inside call to closure at /home/r/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libcore/ops/function.rs:231:5
</pre></div>



<a name="170780645"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20generics/near/170780645" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20generics.html#170780645">(Jul 13 2019 at 08:17)</a>:</h4>
<blockquote>
<p>We may nees to replicate some codegen changes from that PR in the engine</p>
</blockquote>
<p>hm ideally we'd share that code?^^</p>



<a name="170780647"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20generics/near/170780647" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20generics.html#170780647">(Jul 13 2019 at 08:17)</a>:</h4>
<blockquote>
<p>I'll try to find some time next week</p>
</blockquote>
<p>great! it seems to only concern try_from so far so it's not high priority</p>



<a name="170780690"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20generics/near/170780690" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20generics.html#170780690">(Jul 13 2019 at 08:18)</a>:</h4>
<p>hm no there are also other methods</p>



<a name="170780694"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20generics/near/170780694" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20generics.html#170780694">(Jul 13 2019 at 08:18)</a>:</h4>
<p>but none of them are used by the libcore test suite :D</p>



<a name="170780842"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20generics/near/170780842" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20generics.html#170780842">(Jul 13 2019 at 08:23)</a>:</h4>
<p>or maybe they do... but interestingly, other methods seem to work fine</p>



<a name="170781276"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20generics/near/170781276" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20generics.html#170781276">(Jul 13 2019 at 08:36)</a>:</h4>
<p>It may becalling generic methods from generic methods</p>



<a name="170781730"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20generics/near/170781730" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20generics.html#170781730">(Jul 13 2019 at 08:53)</a>:</h4>
<p>what sets it apart from the others is that it <em>uses</em> the const generic <code>N</code> in the body of the code</p>



<a name="170782118"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20generics/near/170782118" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20generics.html#170782118">(Jul 13 2019 at 09:05)</a>:</h4>
<p>Heh, that would make a difference</p>



<a name="170782353"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20generics/near/170782353" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20generics.html#170782353">(Jul 13 2019 at 09:13)</a>:</h4>
<p>Where does the const generic come from</p>



<a name="170782354"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20generics/near/170782354" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20generics.html#170782354">(Jul 13 2019 at 09:13)</a>:</h4>
<p>A local variable's type?</p>



<a name="170782652"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20generics/near/170782652" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20generics.html#170782652">(Jul 13 2019 at 09:25)</a>:</h4>
<p>Ah no, it's using it literally</p>



<a name="170782658"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20generics/near/170782658" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20generics.html#170782658">(Jul 13 2019 at 09:25)</a>:</h4>
<p>Yea we aren't monomorphizing constants yet</p>



<a name="170782659"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20generics/near/170782659" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20generics.html#170782659">(Jul 13 2019 at 09:25)</a>:</h4>
<div class="codehilite"><pre><span></span><span class="w">    </span><span class="k">impl</span><span class="o">&lt;</span><span class="na">&#39;a</span><span class="p">,</span><span class="w"> </span><span class="n">T</span><span class="p">,</span><span class="w"> </span><span class="k">const</span><span class="w"> </span><span class="n">N</span>: <span class="kt">usize</span><span class="o">&gt;</span><span class="w"> </span><span class="n">TryFrom</span><span class="o">&lt;&amp;</span><span class="na">&#39;a</span><span class="w"> </span><span class="k">mut</span><span class="w"> </span><span class="p">[</span><span class="n">T</span><span class="p">]</span><span class="o">&gt;</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="o">&amp;</span><span class="na">&#39;a</span><span class="w"> </span><span class="k">mut</span><span class="w"> </span><span class="p">[</span><span class="n">T</span><span class="p">;</span><span class="w"> </span><span class="n">N</span><span class="p">]</span><span class="w"></span>
<span class="w">    </span><span class="k">where</span><span class="w"></span>
<span class="w">        </span><span class="p">[</span><span class="n">T</span><span class="p">;</span><span class="w"> </span><span class="n">N</span><span class="p">]</span>: <span class="nc">LengthAtMost32</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="k">type</span> <span class="nc">Error</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">TryFromSliceError</span><span class="p">;</span><span class="w"></span>

<span class="w">        </span><span class="k">fn</span> <span class="nf">try_from</span><span class="p">(</span><span class="n">slice</span>: <span class="kp">&amp;</span><span class="nc">mut</span><span class="w"> </span><span class="p">[</span><span class="n">T</span><span class="p">])</span><span class="w"> </span>-&gt; <span class="nb">Result</span><span class="o">&lt;&amp;</span><span class="k">mut</span><span class="w"> </span><span class="p">[</span><span class="n">T</span><span class="p">;</span><span class="w"> </span><span class="n">N</span><span class="p">],</span><span class="w"> </span><span class="n">TryFromSliceError</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">            </span><span class="k">if</span><span class="w"> </span><span class="n">slice</span><span class="p">.</span><span class="n">len</span><span class="p">()</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="n">N</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="c1">// &lt;-- const generic used HERE</span>
<span class="w">                </span><span class="kd">let</span><span class="w"> </span><span class="n">ptr</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">slice</span><span class="p">.</span><span class="n">as_mut_ptr</span><span class="p">()</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="o">*</span><span class="k">mut</span><span class="w"> </span><span class="p">[</span><span class="n">T</span><span class="p">;</span><span class="w"> </span><span class="n">N</span><span class="p">];</span><span class="w"></span>
<span class="w">                </span><span class="k">unsafe</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="nb">Ok</span><span class="p">(</span><span class="o">&amp;</span><span class="k">mut</span><span class="w"> </span><span class="o">*</span><span class="n">ptr</span><span class="p">)</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="w">            </span><span class="p">}</span><span class="w"> </span><span class="k">else</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">                </span><span class="nb">Err</span><span class="p">(</span><span class="n">TryFromSliceError</span><span class="p">(()))</span><span class="w"></span>
<span class="w">            </span><span class="p">}</span><span class="w"></span>
<span class="w">        </span><span class="p">}</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
</pre></div>



<a name="170782701"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20generics/near/170782701" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20generics.html#170782701">(Jul 13 2019 at 09:26)</a>:</h4>
<p>Wherever we get a ty::Const out of the MIR we need to feed it through self.monomorphize</p>



<a name="170782704"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20generics/near/170782704" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20generics.html#170782704">(Jul 13 2019 at 09:26)</a>:</h4>
<p>That should be all that is needed</p>



<a name="170782705"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20generics/near/170782705" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20generics.html#170782705">(Jul 13 2019 at 09:26)</a>:</h4>
<p>really? I can try that or are you on it?</p>



<a name="170782914"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20generics/near/170782914" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20generics.html#170782914">(Jul 13 2019 at 09:34)</a>:</h4>
<p>I am in an airport, so not on it ^^</p>



<a name="170782970"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20generics/near/170782970" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20generics.html#170782970">(Jul 13 2019 at 09:36)</a>:</h4>
<p>May be more efficient to just do it on the ConstValue in the very end</p>



<a name="170782971"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20generics/near/170782971" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20generics.html#170782971">(Jul 13 2019 at 09:36)</a>:</h4>
<p>So we don't intern the monomorphization result</p>



<a name="170783387"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20generics/near/170783387" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20generics.html#170783387">(Jul 13 2019 at 09:53)</a>:</h4>
<p>not sure what you mean, this errors out very early</p>



<a name="170783393"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20generics/near/170783393" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20generics.html#170783393">(Jul 13 2019 at 09:53)</a>:</h4>
<p>so we kind of have to monomorphize early</p>



<a name="170783638"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20generics/near/170783638" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20generics.html#170783638">(Jul 13 2019 at 10:01)</a>:</h4>
<p>We could monomorphize right before that match that errors out</p>



<a name="170783685"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20generics/near/170783685" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20generics.html#170783685">(Jul 13 2019 at 10:02)</a>:</h4>
<p>And match on the result of the monomorphization</p>



<a name="170783689"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20generics/near/170783689" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20generics.html#170783689">(Jul 13 2019 at 10:02)</a>:</h4>
<p>yes that's what I am doing</p>



<a name="170783691"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20generics/near/170783691" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20generics.html#170783691">(Jul 13 2019 at 10:02)</a>:</h4>
<p>I only have a vague memory of the relevant code</p>



<a name="170783692"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20generics/near/170783692" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20generics.html#170783692">(Jul 13 2019 at 10:02)</a>:</h4>
<p>not sure what other option you had in mind</p>



<a name="170783693"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20generics/near/170783693" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20generics.html#170783693">(Jul 13 2019 at 10:02)</a>:</h4>
<p>okay :)</p>



<a name="170783694"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20generics/near/170783694" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20generics.html#170783694">(Jul 13 2019 at 10:02)</a>:</h4>
<p>Oh xD</p>



<a name="170783698"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20generics/near/170783698" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20generics.html#170783698">(Jul 13 2019 at 10:02)</a>:</h4>
<p>Perfect then</p>



<a name="170783707"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20generics/near/170783707" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20generics.html#170783707">(Jul 13 2019 at 10:03)</a>:</h4>
<p>You should be able to write const eval regression tests (if your changes don't cause existing tests to pass)</p>



<a name="170783754"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20generics/near/170783754" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20generics.html#170783754">(Jul 13 2019 at 10:04)</a>:</h4>
<p>cc <span class="user-mention" data-user-id="121053">@varkor</span></p>



<a name="170783872"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20generics/near/170783872" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20generics.html#170783872">(Jul 13 2019 at 10:08)</a>:</h4>
<p>ah, I added a test to Miri but I never know how to fit those into the CTFE restrictions^^</p>



<a name="170783944"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20generics/near/170783944" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20generics.html#170783944">(Jul 13 2019 at 10:11)</a>:</h4>
<p>worst case you can use the <code>const_fn</code> feature gate</p>



<a name="170783987"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20generics/near/170783987" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20generics.html#170783987">(Jul 13 2019 at 10:12)</a>:</h4>
<p>a generic const function that returns its generic parameter as a runtime value should be enough</p>



<a name="170783989"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20generics/near/170783989" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20generics.html#170783989">(Jul 13 2019 at 10:12)</a>:</h4>
<p>(well, and calling it in a const context)</p>



<a name="170783992"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20generics/near/170783992" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20generics.html#170783992">(Jul 13 2019 at 10:12)</a>:</h4>
<p>okay</p>



<a name="170785310"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20generics/near/170785310" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20generics.html#170785310">(Jul 13 2019 at 10:59)</a>:</h4>
<p><span class="user-mention" data-user-id="124288">@oli</span> uh, that <code>monomorphize</code> leads to ICEs...</p>
<div class="codehilite"><pre><span></span>error: internal compiler error: src/librustc/ty/subst.rs:557: type parameter `Self/#0` (Self/0) out of range when substituting (root type=Some(&lt;Self as float::Float&gt;::Int)) substs=[]

thread &#39;rustc&#39; panicked at &#39;Box&lt;Any&gt;&#39;, src/librustc_errors/lib.rs:584:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
error: aborting due to previous error
</pre></div>



<a name="170785364"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20generics/near/170785364" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20generics.html#170785364">(Jul 13 2019 at 11:00)</a>:</h4>
<p>Hmm i've seen that before</p>



<a name="170785368"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20generics/near/170785368" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20generics.html#170785368">(Jul 13 2019 at 11:00)</a>:</h4>
<p>I have a PR working on it</p>



<a name="170785371"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20generics/near/170785371" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20generics.html#170785371">(Jul 13 2019 at 11:00)</a>:</h4>
<p>We are doing monomorphizations the wrong way iirc</p>



<a name="170785382"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20generics/near/170785382" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20generics.html#170785382">(Jul 13 2019 at 11:01)</a>:</h4>
<p>Like we take the wrong substs</p>



<a name="170785433"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20generics/near/170785433" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20generics.html#170785433">(Jul 13 2019 at 11:03)</a>:</h4>
<p>is that <a href="https://github.com/rust-lang/rust/pull/61041" target="_blank" title="https://github.com/rust-lang/rust/pull/61041">https://github.com/rust-lang/rust/pull/61041</a>?</p>



<a name="170791750"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20generics/near/170791750" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20generics.html#170791750">(Jul 13 2019 at 14:22)</a>:</h4>
<p>Jop</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>